<template>
  <div class="app-container">
    <!-- Header 区域 -->
    <es-header></es-header>

    <!-- 商品 Item 项组件 -->
    <es-goods 
    v-for="item in list"
    :key="item.goods_id"
      :id="item.goods_id" 
      :title="item.goods_name" 
      :thumb="item.goods_img" 
      :price="item.goods_price" 
      :count="item.goods_count" 
      :state="item.goods_state" 
      @stateChange="getState" 
      @countChange="getCount">
    </es-goods>

    <!-- Foote 区域 -->
    <es-footer></es-footer>
  </div>
</template>

<script>
import EsHeader from '@/components/Header.vue'
import EsFooter from '@/components/Footer.vue'
import EsGoods from '@/components/Goods.vue'
import { mapState } from 'vuex'

export default {
  name: 'App',
  computed:{
    ...mapState('cart',['list'])
  },
  methods: {
    // 商品的选中状态发生了变化
    getState(obj) {
      // {id: 1, state: false}
      console.log(obj)
    },
    // 商品的数量发生了变化
    getCount(obj) {
      // {id: 1, count: 2}
      console.log(obj)
    },
  },
  components: {
    EsHeader,
    EsFooter,
    EsGoods,
  },
  created(){
    this.$store.dispatch('cart/getList')
  }
}
</script>

<style lang="less" scoped>
.app-container {
  padding: 46px 0 50px 0;
}
</style>